package com.yuedou.api.service.wxuser.impl;

import com.yuedou.api.dao.wxuser.UserTransactionMapper;
import com.yuedou.api.entity.wxuser.User;
import com.yuedou.api.entity.wxuser.UserTransaction;
import com.yuedou.api.service.base.impl.BaseServiceImpl;
import com.yuedou.api.service.wxuser.UserService;
import com.yuedou.api.service.wxuser.UserTransactionService;
import com.vdurmont.emoji.EmojiParser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserTransactionServiceImpl extends BaseServiceImpl<UserTransactionMapper, UserTransaction> implements UserTransactionService {
    @Resource
    private UserTransactionMapper userTransactionMapper;
    @Resource
    private UserService userService;

    @Override
    public List<UserTransaction> selectByUserId(Integer user_id, Integer user_type,int offset,int pageSize) {
        List<UserTransaction> userTransactions = userTransactionMapper.selectByUserId(user_id,user_type,offset,pageSize);
        if(userTransactions != null && userTransactions.size() > 0){
            for (UserTransaction userTransaction : userTransactions){
                User user1 = userService.findById(userTransaction.getUserId());
                if(user1 != null){
                    if(user1.getNickName()!=null){
                        userTransaction.setNicknameNormal(EmojiParser.parseToUnicode(user1.getNickName()));
                    }
                    userTransaction.setNormalFaceUrl(user1.getFaceUrl());
                }
                User user2 = userService.findById(userTransaction.getShopId());
                if(user2!=null){
//                    userTransaction.setShopLogo(user2.getShopLogo());
//                    userTransaction.setShopName(user2.getShopName());
                }
            }
        }
        return userTransactions;
    }
}
